package com.fitbet.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fitbet.entity.bet.UserBet;
import com.fitbet.entity.bet.UserBetStatus;
import com.fitbet.entity.bet.UserBetSupport;
import com.fitbet.entity.user.Wallet;

/**
 * @author xiaoHU
 *
 */
@Dao("hibernate")
public interface UserBetDao {

    /**
     * @param status
     */
    @Query("SELECT COUNT(*) FROM UserBet  WHERE status =:status AND disabled = false")
    public int count(@Variable("status") UserBetStatus status);

    /**
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM UserBet WHERE status =:status AND disabled = false")
    public List<UserBet> list(@Variable("status") UserBetStatus status, @Variable("beginIndex") int beginIndex,@Variable("maxResult") int maxResult); 
    
    /**
     * 
     * @param userBetId
     * @return
     */
    @Query("FROM UserBetSupport WHERE userBet.id =:userBetId AND disabled = false")
    public List<UserBetSupport> listById(@Variable("userBetId") Long userBetId);
    
    /**
     * 
     * @param userBetId
     * @return
     */
    @Query("FROM UserBetSupport WHERE userBet.id =:userBetId AND disabled = false AND support = true")
    public List<UserBetSupport> listByIdAndSupportIsTrue(@Variable("userBetId") Long userBetId);
    
   /**
    * 
    * @param userBetId
    * @return
    */
    @Query("FROM UserBetSupport WHERE userBet.id =:userBetId AND disabled = false AND support = false")
    public List<UserBetSupport> listByIdAndSupportIsFalse(@Variable("userBetId") Long userBetId);
    
    /**
     * 
     * @param userId
     * @return
     */
    @Query("FROM Wallet WHERE user.id = :userId")
    public Wallet load(@Variable("userId") Long userId);
}
